﻿// <copyright file="MediaRssItem.cs" company="Ucaya">
// </copyright>
// <author>Ucaya</author>

namespace MediaRss
{
    #region

    using System;
    using System.ServiceModel.Syndication;
    using System.Xml;

    #endregion

    public class MediaRssItem : SyndicationItem
    {
        #region Constants and Fields

        private Backlinks backlinksNode;

        private Comments commentsNode;

        private Community communityNode;

        private Content contentNode;

        private Contents contentsNode;

        private Embed embedNode;

        private License licenseNode;

        private PeerLink peerLinkNode;

        private Price priceNode;

        private Responses responsesNode;

        private Restriction restrictionNode;

        private Scenes scenesNode;

        private Status statusNode;

        private SubTitle subTitleNode;

        private Thumbnail thumbnailNode;

        private Thumbnails thumbnailsNode;

        #endregion

        #region Constructors and Destructors

        public MediaRssItem()
        {
        }

        public MediaRssItem(string title, string content, Uri itemAlternateLink, string id, DateTimeOffset lastUpdatedTime)
                : base(title, content, itemAlternateLink, id, lastUpdatedTime)
        {
        }

        #endregion

        #region Public Properties

        public Backlinks BacklinksNode
        {
            get
            {
                return this.backlinksNode;
            }
        }

        public Comments CommentsNode
        {
            get
            {
                return this.commentsNode;
            }
        }

        public Community CommunityNode
        {
            get
            {
                return this.communityNode;
            }
        }

        public Content ContentNode
        {
            get
            {
                return this.contentNode;
            }
        }

        public Contents ContentsNode
        {
            get
            {
                return this.contentsNode;
            }
        }

        public Embed EmbedNode
        {
            get
            {
                return this.embedNode;
            }
        }

        public License LicenseNode
        {
            get
            {
                return this.licenseNode;
            }
        }

        public PeerLink PeerLinkNode
        {
            get
            {
                return this.peerLinkNode;
            }
        }

        public Price PriceNode
        {
            get
            {
                return this.priceNode;
            }
        }

        public Responses ResponsesNode
        {
            get
            {
                return this.responsesNode;
            }
        }

        public Restriction RestrictionNode
        {
            get
            {
                return this.restrictionNode;
            }
        }

        public Scenes ScenesNode
        {
            get
            {
                return this.scenesNode;
            }
        }

        public Status StatusNode
        {
            get
            {
                return this.statusNode;
            }
        }

        public SubTitle SubTitleNode
        {
            get
            {
                return this.subTitleNode;
            }
        }

        public Thumbnail ThumbnailNode
        {
            get
            {
                return this.thumbnailNode;
            }
        }

        public Thumbnails ThumbnailsNode
        {
            get
            {
                return this.thumbnailsNode;
            }
        }

        #endregion

        #region Methods

        protected override bool TryParseElement(XmlReader reader, string version)
        {
            bool flag = false;
            if (!(version == "Rss20") || !(reader.NamespaceURI == "http://search.yahoo.com/mrss/"))
            {
                return flag;
            }
            switch (reader.LocalName)
            {
                case "content":
                    this.contentNode = new Content();
                    this.ContentNode.ReadXml(reader);
                    return true;

                case "community":
                    this.communityNode = new Community();
                    this.CommunityNode.ReadXml(reader);
                    return true;

                case "comments":
                    this.commentsNode = new Comments();
                    this.CommentsNode.ReadXml(reader);
                    return true;

                case "responses":
                    this.responsesNode = new Responses();
                    this.ResponsesNode.ReadXml(reader);
                    return true;

                case "backLinks":
                    this.backlinksNode = new Backlinks();
                    this.BacklinksNode.ReadXml(reader);
                    return true;

                case "thumbnails":
                    this.thumbnailsNode = new Thumbnails();
                    this.ThumbnailsNode.ReadXml(reader);
                    return true;

                case "group":
                    this.contentsNode = new Contents();
                    this.ContentsNode.ReadXml(reader);
                    return true;

                case "thumbnail":
                    this.thumbnailNode = new Thumbnail();
                    this.ThumbnailNode.ReadXml(reader);
                    return true;

                case "embed":
                    this.embedNode = new Embed();
                    this.EmbedNode.ReadXml(reader);
                    return true;

                case "price":
                    this.priceNode = new Price();
                    this.PriceNode.ReadXml(reader);
                    return true;

                case "license":
                    this.licenseNode = new License();
                    this.LicenseNode.ReadXml(reader);
                    return true;

                case "peerLink":
                    this.peerLinkNode = new PeerLink();
                    this.PeerLinkNode.ReadXml(reader);
                    return true;

                case "subTitle":
                    this.subTitleNode = new SubTitle();
                    this.SubTitleNode.ReadXml(reader);
                    return true;

                case "restriction":
                    this.restrictionNode = new Restriction();
                    this.RestrictionNode.ReadXml(reader);
                    return true;

                case "status":
                    this.statusNode = new Status();
                    this.StatusNode.ReadXml(reader);
                    return true;

                case "scenes":
                    this.scenesNode = new Scenes();
                    this.ScenesNode.ReadXml(reader);
                    return true;
            }
            return base.TryParseElement(reader, version);
        }

        protected override void WriteElementExtensions(XmlWriter writer, string version)
        {
            if (version == "Rss20")
            {
                if (this.ContentNode != null)
                {
                    writer.WriteStartElement("media", "content", "http://search.yahoo.com/mrss/");
                    this.ContentNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.CommunityNode != null)
                {
                    writer.WriteStartElement("media", "community", "http://search.yahoo.com/mrss/");
                    this.CommunityNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.CommentsNode != null)
                {
                    writer.WriteStartElement("media", "comments", "http://search.yahoo.com/mrss/");
                    this.CommentsNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.ResponsesNode != null)
                {
                    writer.WriteStartElement("media", "responses", "http://search.yahoo.com/mrss/");
                    this.ResponsesNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.BacklinksNode != null)
                {
                    writer.WriteStartElement("media", "backLinks", "http://search.yahoo.com/mrss/");
                    this.BacklinksNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.ThumbnailsNode != null)
                {
                    writer.WriteStartElement("media", "thumbnails", "http://search.yahoo.com/mrss/");
                    this.ThumbnailsNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.EmbedNode != null)
                {
                    writer.WriteStartElement("media", "embed", "http://search.yahoo.com/mrss/");
                    this.EmbedNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.SubTitleNode != null)
                {
                    writer.WriteStartElement("media", "subTitle", "http://search.yahoo.com/mrss/");
                    this.SubTitleNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.PeerLinkNode != null)
                {
                    writer.WriteStartElement("media", "peerLink", "http://search.yahoo.com/mrss/");
                    this.PeerLinkNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.LicenseNode != null)
                {
                    writer.WriteStartElement("media", "license", "http://search.yahoo.com/mrss/");
                    this.LicenseNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.PriceNode != null)
                {
                    writer.WriteStartElement("media", "price", "http://search.yahoo.com/mrss/");
                    this.PriceNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.RestrictionNode != null)
                {
                    writer.WriteStartElement("media", "restriction", "http://search.yahoo.com/mrss/");
                    this.RestrictionNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
                if (this.StatusNode != null)
                {
                    writer.WriteStartElement("media", "status", "http://search.yahoo.com/mrss/");
                    this.StatusNode.WriteXml(writer);
                    writer.WriteEndElement();
                }
            }
            base.WriteElementExtensions(writer, version);
        }

        #endregion
    }
}